<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<h1>
	<fmt:message key="person.list.title" />
</h1>
<table class="search">
	<tr>
		<th><fmt:message key="person.form.firstName" /></th>
		<th><fmt:message key="person.form.lastName" /></th>
		<th><fmt:message key="person.form.age" /></th>
		<th><fmt:message key="person.form.email" /></th>
		<th><fmt:message key="person.form.mobile" /></th>
	</tr>
	<c:forEach var="person" items="${list}" varStatus="status">
		<tr>
			<c:set var="personFormId" value="person${status.index}" />

			<c:url var="editUrl" value="/person/form.html">
				<c:param name="id" value="${person.id}" />
			</c:url>

			<sec:authorize ifAllGranted="ROLE_ADMIN">
				<c:url var="deleteUrl" value="/person/delete.html" />
				<form id="${personFormId}" action="${deleteUrl}" method="POST">
					<input id="id" name="id" type="hidden" value="${person.id}" />
				</form>
			</sec:authorize>

			<td>${person.firstName}</td>
			<td>${person.lastName}</td>
			<td>${person.age}</td>
			<td>${person.email}</td>
			<td>${person.mobile}</td>
			<td><a href='<c:out value="${editUrl}"/>'><fmt:message
						key="button.edit" /></a> <sec:authorize ifAllGranted="ROLE_ADMIN">
					<a href="javascript:document.forms['${personFormId}'].submit();"><fmt:message
							key="button.delete" /></a>


				</sec:authorize></td>
		</tr>
	</c:forEach>
</table>